﻿//搜索点赞评论
function main() {
    var testVersion = "(201901021555)版";
    var softwareName = "抖音";
    var view = RequestEngine.getWebView();
    var viewJson = JSON.parse(view);
    var search = viewJson.search;
    var zanPinType = viewJson.issixin; //是否评论  0 不  1 发
    var fanYeNum = viewJson.fenSiNum; //评论个数
    var contentArr = viewJson.contentArr;
    var dengdai = viewJson.dengdai;
    AccessibilityEngine.sleepEngine(5000);// 等待

    // chuSiHua(widget.pages.shouye.bugengxin);
	if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    var jixing = getXYByIdIndex(widget.pages.shouye.wode);
	if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.mockOnClickId(widget.pages.shouye.shousuo); // 点击搜索 放大镜
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
	//点击赋值框
     if( jixing == 1 ){
        ScreenEngine.swipe(parseX(300), parseY(100), parseX(300), parseY(100), 500); //点击
    } else if( jixing == 2 ){
        ScreenEngine.swipe(parseX(400), parseY(100), parseX(400), parseY(100), 500); //点击
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.sleepEngine(2000);//等待
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.mockEditId(widget.pages.shouye.shousuopinglunKuang, search); //赋值搜索框
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.sleepEngine(2000);//等待


    //搜索按钮
    if (jixing == 1) {
        ScreenEngine.swipe(parseX(665), parseY(1219), parseX(665), parseY(1219), 500); //点击
    } else if (jixing == 2) {
		AccessibilityEngine.sleepEngine(5000);//等待
		//ScreenEngine.swipe(parseX(480), parseY(715), parseX(480), parseY(715), 500); //点击
		ScreenEngine.swipe(parseX(700), parseY(1200), parseX(700), parseY(1200), 500); //点击 		
    }
	
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.sleepEngine(1000);//等待
    if (AccessibilityEngine.checkUpIdText("android:id/text1", "视频") == ISTRUE) {
        AccessibilityEngine.mockOnClickIdText("android:id/text1", "视频"); // 点击视频

    }
	AccessibilityEngine.sleepEngine(8000);//等待
    ScreenEngine.swipe(parseX(176), parseY(455), parseX(176), parseY(455), 500); //点击第一个视频
    AccessibilityEngine.sleepEngine(1000);//等待
	
	 if( jixing == 1 ){// 判断机型
                var pressjixing = "press," + parseX(660) + "," + parseY(757);
                ScreenEngine.currency(pressjixing);
            } else if( jixing == 2 ){
                ScreenEngine.swipe(parseX(667), parseY(760), parseX(667), parseY(760), 500); //从下往上滑动
            }
	AccessibilityEngine.sleepEngine(2000);//等待
	if (AccessibilityEngine.checkUpIdText(widget.pages.fasongxiaoxi.plzf, "评论并转发")==ISTRUE){
            
            AccessibilityEngine.mockBack();
            AccessibilityEngine.sleepEngine(2000);//等待
            ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 500); //从下往上滑动
			AccessibilityEngine.sleepEngine(2000);//等待
			if (jixing == 1) {
				ScreenEngine.swipe(parseX(663), parseY(746), parseX(663), parseY(746), 500); //点击
			} else if (jixing == 2) {
				ScreenEngine.swipe(parseX(987), parseY(1119), parseX(987), parseY(1119), 500); //点击
			}
    }

	if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
		AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
	}
	AccessibilityEngine.sleepEngine(dengdai*1000);//等待
	if (zanPinType == 0) {
		dianZan();
	} else if (zanPinType == 1) {
		dianZan();
		pinPun();
	}
    setTaskState("5", "执行成功");
    throw SyntaxError();

    function dianZan() {
         //var zanIdNum = AccessibilityEngine.getIdNum("com.ss.android.ugc.aweme:id/b4b");
		 for (var zan = 0; zan < fanYeNum; zan++) {
			if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
				AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
			}
			if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
				AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
			}
			AccessibilityEngine.sleepEngine(300);//等待
			AccessibilityEngine.mockOnClickIdIndex("com.ss.android.ugc.aweme:id/bfs", zan); //逐个小心
		}
    }

    function pinPun() {
        if (AccessibilityEngine.checkUpId(widget.pages.shouye.pinglunKuang) == ISTRUE) {
            AccessibilityEngine.mockOnClickId(widget.pages.shouye.pinglunKuang); // 点击评论
            AccessibilityEngine.sleepEngine(1000);//等待
            var paramContent = contentArr[Math.floor(Math.random() * contentArr.length)];
            AccessibilityEngine.mockEditId(widget.pages.shouye.pinglunKuang, paramContent); //赋值
            AccessibilityEngine.mockOnClickId(widget.pages.shouye.fasong); // 发送
            AccessibilityEngine.sleepEngine(1000)
            if (AccessibilityEngine.getEditText(widget.pages.shouye.pinglunKuang) == paramContent) {
                AccessibilityEngine.mockBack();
            }
            AccessibilityEngine.sleepEngine(3000);//等待
        }
    }
}

var publicfunction = RequestEngine.getPluginPath() + "OS_DYCOMMON/publicfunction.js";
include(publicfunction); //公共方法js
var widgetPath = dyConditionCheck();
var widgetbyid = RequestEngine.getPluginPath() +"OS_DYCOMMON/"+ widgetPath;
include(widgetbyid);
main();